package com.zj.service.impl;

import com.zj.dao.UserDao;
import com.zj.pojo.User;
import com.zj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    public int balanceInById(int id,float balance) {
        return userDao.balanceInById(id,balance);
    }

    public int balanceOutById(int id,float balance) {
        return userDao.balanceInById(id,balance);
    }
    //转账操作
    public List<User> transfer(User outUser,User inUser,float balance){
        userDao.balanceInById(inUser.getUserid(),balance);
        //int a=1/0;
        userDao.balanceOutById(outUser.getUserid(),balance);
        List<User> list = new ArrayList();
        outUser = userDao.selectByDId(outUser.getUserid());
        inUser = userDao.selectByDId(inUser.getUserid());
        list.add(outUser);
        list.add(inUser);
        return list;
    }

}
